<template>
	<view class="all-box">
		<!-- 抢券 -->
		<view class="coupon-list">
			<view class="list-box">
				<view class="list-left-top">
					优惠券
				</view>

				<!-- 抢券按钮 -->
				<view class="rob-tick" @click="robClick">
					抢券
				</view>
				<view class="check-tick">
					<u--text type="primary" @click="checkTick" class="check-text-btn" align="center" lineHeight="80"
						suffixIcon="arrow-right" size="25"
						iconStyle="font-size: 12px;position:relative;top:1px;color:#3c9cff" text="我的优惠券"></u--text>
				</view>


			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listInfo: [],
				openId: '',
				unionId: '',
				typeValue: '1',
				ids: '',
				fromUnionId: '',
				voucher: '',
				endUnionId: '',
			}
		},
		onLoad(e) {
			console.log("下面是你要的东西")
			console.log(e)
			this.ids = e.id
			this.fromUnionId = e.fromUnionId
			this.getRobCouponVoucher()
			let a = uni.getStorageSync('_otherUserInfo')
			this.endUnionId = a.unionId
		},
		onShow() {
			let a = uni.getStorageSync('_otherUserInfo')
			console.log("其他登录人信息")
			console.log(a)
			console.log("其他登录人信息")
			let openId = uni.getStorageSync('openId')
			console.log("这是openId", openId)
			this.unionId = openId.unionid
			this.openId = openId.openid
			this.getCouponLists()
		},
		methods: {
			// 优惠券-获取抢券链接凭证
			getRobCouponVoucher() {
				this.$api.queryRobCouponVoucher(this.ids, this.fromUnionId).then(res => {
					console.log(" 优惠券-获取抢券链接凭证")
					if (res.success) {
						this.voucher = res.result
					}
				})
			},
			getCouponLists() {
				let data = {
					useState: this.typeValue,
					unionId: this.unionId
				}
				this.$api.getCouponList(data).then(res => {
					console.log(res)
					if (res.success) {
						this.listInfo = res.result.records
					}
				})
			},
			// 抢券
			robClick() {
				console.log(1)

				this.$api.robCouponVoucher(this.voucher, this.endUnionId).then(res => {
					console.log(res)
					if (res.success) {
						uni.showToast({
							title: res.result,
							icon: 'none'
						});
					}
				})
			},
			// 查看优惠券
			checkTick() {
				console.log('查看我的优惠券')
				uni.navigateTo({
					url: '/pagesBusiness/coupon/receiveCoupon'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.all-box {
		background-color: #F8F9FF;
		padding: 0 30upx 20upx;
		position: relative;

		// 优惠券列表
		.coupon-list {

			// .coupon-active{
			// 	color: red;
			// }
			// 单个优惠券box
			.list-box {
				// display: flex;
				position: relative;
				// width: 700upx;
				// height: 300upx;
				border-radius: 20upx;
				background: #FFFFFF;
				box-shadow: 5px 5px 3px #888888;
				border: 1px solid rgba(0, 0, 0, 0.1);
				margin: 40upx auto;

				// 优惠券左上角显示的背景图
				.list-left-top {
					// position: absolute;
					// top: 10upx;
					// left: -15upx;
					margin: 20upx auto;
					width: 240upx;
					height: 80upx;
					text-align: center;
					line-height: 80upx;
					font-size: 26upx;
					color: white;
					letter-spacing: 8upx;
					background: linear-gradient(90deg, #ff9c11 0%, #ff2819 100%);
					// transform: rotateZ(-30deg);
				}

				// 抢券
				.rob-tick {
					margin: 80upx auto 0;
					width: 150upx;
					height: 150upx;
					border-radius: 50%;
					text-align: center;
					line-height: 150upx;
					background: linear-gradient(90deg, #ff9c11 0%, #ff2819 100%);
					font-size: 26upx;
					color: white;
				}

				.check-tick {
					text-align: center;

					.check-text-btn {
						margin: 10upx auto !important;
						text-align: center;
					}
				}
			}




		}

	}
</style>
